package com.zzyl.nursing.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.dto.CancelTaskDto;
import com.zzyl.nursing.dto.DoTaskDto;
import com.zzyl.nursing.dto.UpdateTimeDto;
import com.zzyl.nursing.service.INursingTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 护理任务Controller
 * 
 * @author ruoyi
 * @date 2025-10-09
 */
@RestController
@RequestMapping("/nursing/nursingTask")
@Api(tags = "护理任务的接口")
public class NursingTaskController extends BaseController
{
    @Autowired
    private INursingTaskService nursingTaskService;

    /**
     * 查询护理任务列表
     */
    @ApiOperation("查询护理任务列表")
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(NursingTask nursingTask)
    {
        startPage();
        List<NursingTask> list = nursingTaskService.selectNursingTaskList(nursingTask);
        return getDataTable(list);
    }

    /**
     * 导出护理任务列表
     */
    @ApiOperation("导出护理任务列表")
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:export')")
    @Log(title = "护理任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NursingTask nursingTask)
    {
        List<NursingTask> list = nursingTaskService.selectNursingTaskList(nursingTask);
        ExcelUtil<NursingTask> util = new ExcelUtil<NursingTask>(NursingTask.class);
        util.exportExcel(response, list, "护理任务数据");
    }

    /**
     * 获取护理任务详细信息
     */
    @ApiOperation("获取护理任务详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "护理任务ID", required = true)
            @PathVariable("id") Long id)
    {
        return success(nursingTaskService.selectNursingTaskById(id));
    }

    /**
     * 新增护理任务
     */
    @ApiOperation("新增护理任务")
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:add')")
    @Log(title = "护理任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(value = "护理任务实体")
            @RequestBody NursingTask nursingTask)
    {
        return toAjax(nursingTaskService.insertNursingTask(nursingTask));
    }

    /**
     * 修改护理任务
     */
    @ApiOperation("修改护理任务")
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:edit')")
    @Log(title = "护理任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "护理任务实体")
            @RequestBody NursingTask nursingTask)
    {
        return toAjax(nursingTaskService.updateNursingTask(nursingTask));
    }

    /**
     * 删除护理任务
     */
    @ApiOperation("删除护理任务")
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:remove')")
    @Log(title = "护理任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nursingTaskService.deleteNursingTaskByIds(ids));
    }


    /**
     * 取消护理任务
     *
     * @param dto 取消任务的数据传输对象，包含任务取消的相关信息
     * @return AjaxResult 操作结果，包含操作是否成功的状态信息
     */
    @ApiOperation("取消护理任务")
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:cancel')")
    @Log(title = "护理任务", businessType = BusinessType.UPDATE)
    @PutMapping("/cancel")
    public AjaxResult cancel(@RequestBody CancelTaskDto dto) {
        AjaxResult result = nursingTaskService.cancelNursingTask(dto);
        return result;
    }


    /**
     * 执行护理任务
     * @param dto 护理任务执行参数对象，包含任务ID和执行信息
     * @return AjaxResult 执行结果，包含操作状态和返回数据
     */
    @ApiOperation("执行护理任务")
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:do')")
    @Log(title = "护理任务", businessType = BusinessType.UPDATE)
    @PutMapping("/do")
    public AjaxResult doTask(@RequestBody DoTaskDto dto) {
        // 调用服务层执行护理任务操作
        return nursingTaskService.doNursingTask(dto);
    }



    /**
     * 任务改期接口
     *
     * @param dto 包含任务改期信息的数据传输对象
     * @return AjaxResult 操作结果，包含成功或失败信息
     */
    @ApiOperation("任务改期")
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:updateTime')")
    @Log(title = "护理任务", businessType = BusinessType.UPDATE)
    @PutMapping("/updateTime")
    public AjaxResult updateTime(@RequestBody UpdateTimeDto dto) {
        // 调用服务层执行任务时间更新操作
        return nursingTaskService.updateTaskTime(dto);
    }



}
